<?php
//跨域设置
header("Access-Control-Allow-Origin:*");
//开启session
session_start();
$users = [
    ["username" => "张三", "password" => "1", "age" => "18"],
    ["username" => "李四", "password" => "2", "age" => "19"],
    ["username" => "王五", "password" => "3", "age" => "20"],
];
//接收用户的输入
if (!empty($_REQUEST['username']) && !empty($_REQUEST['password'])) {
    //判断用户名和密码是否正确
    //张三
    array_filter($users, function ($v) {
        if ($v['username'] == $_REQUEST['username'] && $v['password'] == $_REQUEST['password']) {
            //将用户信息存入session
            $_SESSION['user'] = $v;
            echo json_encode(['code' => 200, 'msg' => 'success']);
        } else {
            echo json_encode(['code' => 401, 'msg' => 'login fail ']);
        }
    });
}
